Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:'',
    afterSale:"return-change",
    
    goodsArr: [
      {
        id: 1,
        title: '商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品1',
        num: 1,
        price: 10,
        selected: false,
        img:"../../../images/goods-test.png"
      },
      {
        id: 2,
        title: '商品2',
        num: 2,
        price: 5,
        selected: true,
        img:"../../../images/goods-test.png"
      },
      {
        id:3,
        title: '商品3',
        num: 2,
        price: 15,
        selected: false,
        img:"../../../images/goods-test.png"
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type:options.choosetype
    })
    if(this.data.type == "return"){
      wx.setNavigationBarTitle({
        title: '选择退货商品' // 导航栏标题
      });
    }else{
      wx.setNavigationBarTitle({
        title: '选择换货商品' // 导航栏标题
      });
    }
  },
// 单个选
  select:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var goodsArr = this.data.goodsArr;
     that.data.selectAllFlag = true;
    goodsArr[index].selected = !goodsArr[index].selected;
    for(var i = goodsArr.length - 1;i >= 0; i--){
      if(!goodsArr[i].selected){
        that.data.selectAllFlag = false;
        break
      }
    }
    that.setData({
      goodsArr:goodsArr,
      selectAllFlag:that.data.selectAllFlag
    });
  },
  // 全选
  selectAll: function (e) {
    var that= this;
    let selectAllFlag = this.data.selectAllFlag;
    selectAllFlag = !selectAllFlag;
    //获得购物车所有的商品
    let goodsArr = this.data.goodsArr;
    for (let i = 0; i < goodsArr.length; i++) {
      //设置每个商品的选中标识
      goodsArr[i].selected = selectAllFlag;
    }
    that.setData({
      selectAllFlag: selectAllFlag,
      goodsArr: goodsArr
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function (options) {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  returnNextStep:function(){
    console.log("return")
    wx.navigateTo({
      url: '../apply-return-change/index?applytype=' + 'return', // 指定页面的url
    });
  },
  changeNextStep:function(){
    console.log("change")

    wx.navigateTo({
      url: '../apply-return-change/index?applytype=' + 'change', // 指定页面的url
    });
  },
})